package es.deusto.ingenieria.BlWhSquares;

import java.util.Vector;

import es.deusto.ingenieria.is.search.formulation.State;

public class BlWhSquaresEnvironment extends State implements Cloneable {
	private Vector<String> squares;
	private int posRobot;

	public BlWhSquaresEnvironment(Vector<String> squares, int posRobot) {
		super();
		this.squares = squares;
		this.posRobot = posRobot;
	}

	public boolean equals(Object object) {
		boolean x = false;
		if (object != null && object instanceof BlWhSquaresEnvironment) {
			if (((BlWhSquaresEnvironment) object).getPosition() == this
					.getPosition()) {
				x = true;
			} else {
				x = false;
			}
		}
		return x;
	}

	@Override
	public String toString() {
		String s = "-";
		for (int i = 0; i < squares.size(); i++) {
			if (squares.get(i) == "black")
				s = s + "B";
			if (squares.get(i) == "white")
				s = s + "W";
			if (i == posRobot)
				s = s + "R";
			s = s + "-";
		}
		
		return s;
	}

	public Vector<String> getSquares() {
		return squares;
	}

	public void setSquares(Vector<String> squares) {
		this.squares = squares;
	}

	public int getPosition() {
		return posRobot;
	}

	public void setPosition(int position) {
		this.posRobot = position;
	}

	public BlWhSquaresEnvironment Clone() {
		BlWhSquaresEnvironment enviroment = new BlWhSquaresEnvironment(
				this.squares, this.posRobot);
		return enviroment;
	}

	public static void main(String[] args) {
		Vector<String> squares = new Vector<String>();
		squares.add("white");
		squares.add("white");
		squares.add("black");
		squares.add("white");
		squares.add("white");
		squares.add("black");

		BlWhSquaresEnvironment entorno = new BlWhSquaresEnvironment(squares, 1);
		BlWhSquaresEnvironment entorno2 = new BlWhSquaresEnvironment(squares, 2);
		BlWhSquaresEnvironment entornoClone = entorno.Clone();
		System.out.println("Comparando entorno con entorno2");
		System.out.println(entorno.toString() + "  ==  " + entorno2.toString());
		if (entorno.equals(entorno2)) {
			System.out.println("Son iguales");
		} else {
			System.out.println("No Son iguales");
		}

		System.out.println("Entorno clonado: " + entorno.toString());
		System.out.println("Entorno clon: " + entornoClone.toString());
		if (entorno.equals(entornoClone))
			System.out.println("son clones");

		BlWhSquaresEnvironment entorno4 = new BlWhSquaresEnvironment(squares, 4);
		BlWhSquaresEnvironment entorno3 = new BlWhSquaresEnvironment(squares, 3);
		System.out.println("Comparando entorn4 con entorno3");
		System.out.println(entorno4.toString() + "  ==  " + entorno3.toString());
		if (entorno4.equals(entorno3)) {
			System.out.println("Son iguales");
		} else {
			System.out.println("No Son iguales");
		}

	}

}
